# -*- mode: Makefile -*-

# Handle builds both with and without a git repository
ifeq ($(shell test -d ../.git && echo yes),yes)
GITREV = $$(git describe --always --tags)
GITREV_FOR_PKG = $(shell echo "$(GITREV)" | sed -e 's,-,\.,g' -e 's,^v,,')
GITTIMESTAMP = $$(git show --no-patch --format=%ci)
else
# Fallback when no git repo is available
GITREV = unknown
GITREV_FOR_PKG = 9999.0.0
GITTIMESTAMP = $(shell date -u +"%Y-%m-%d %H:%M:%S %z")
endif

srcdir=$(shell dirname `pwd`)
PACKAGE=rpm-ostree

PKG_VER = $(PACKAGE)-$(GITREV_FOR_PKG)
PKG_CLIENT_VER = $(PACKAGE)-client-$(GITREV_FOR_PKG)

dist-snapshot:
	./make-git-snapshot.sh "$(srcdir)" "$(PKG_VER)" "$(GITREV)" "$(GITTIMESTAMP)"
	rm -f $(PKG_VER).tar.xz
	xz -T0 $(PKG_VER).tar

srpm: dist-snapshot
	 sed -e "s,^Version:.*,Version: $(GITREV_FOR_PKG)," $(PACKAGE).spec > $(PACKAGE).spec.new; \
	 mv $(PACKAGE).spec.new $(PACKAGE).spec; \
	 ./rpmbuild-cwd -bs $(PACKAGE).spec

rpm: srpm
	./rpmbuild-cwd --rebuild $(PKG_VER)*.src.rpm

yumrepo: rpm
	repomanage -o . | xargs -r rm
	createrepo_c .
